package com.agentframework.core.agent;

import com.agentframework.core.action.Action;

import java.util.List;

/**
 * @author wangjun
 **/
public class InOrderReactStrategy implements ReactStrategy {

    @Override
    public boolean react(Agent agent) {
        if (agent instanceof AbstractAgent aagent) {
            AgentContext context = aagent.context;
            List<Action> actionList = aagent.actions;

            if (context.getMaxReactLoop() != actionList.size()) {
                context.setMaxReactLoop(actionList.size());
            }
            aagent.setActionIndex(context.getActionIndex() + 1);
            return context.getActionIndex() >= 0 && context.getActionIndex() < actionList.size();
        }
        return false;
    }

}
